<?php
class User extends AppModel {
	var $name = 'User';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $actsAs = array('Acl' => array('type' => 'requester'));
	
	var $virtualFields = array(
		'nombre_completo' => 'CONCAT(UCASE(SUBSTRING(User.apellido,1,1)), LOWER(SUBSTRING(User.apellido,2)), 
    						  " ", UCASE(SUBSTRING(User.nombre,1,1)), LOWER(SUBSTRING(User.nombre,2)))'		
    );
    
    
	function parentNode() {
    	if (!$this->id && empty($this->data)) {
    		return null;
    	}
    	if (isset($this->data['User']['group_id'])) {
    		$groupId = $this->data['User']['group_id'];
    	} else {
    		$groupId = $this->field('group_id');
    	}
    	if (!$groupId) {
    		return null;
    	} else {
    		return array('Group' => array('id' => $groupId));
    	}
    }

    function bindNode($user) {
    	return array('model' => 'Group', 'foreign_key' => $user['User']['group_id']);
    }
	
	var $belongsTo = array(
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Informefinale' => array(
			'className' => 'Informefinale',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Informemensuale' => array(
			'className' => 'Informemensuale',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Informemomento' => array(
			'className' => 'Informemomento',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Informeproceso' => array(
			'className' => 'Informeproceso',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);


	var $hasAndBelongsToMany = array(
		'Municipio' => array(
			'className' => 'Municipio',
			'joinTable' => 'municipios_users',
			'foreignKey' => 'user_id',
			'associationForeignKey' => 'municipio_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

}
